import 'package:bxultimate/shared/shared.dart';
import 'package:get/get.dart';

import 'state.dart';

class UserPrivacyRecommandController extends GetxController {
  final UserPrivacyRecommandState state = UserPrivacyRecommandState();

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();

    state.positionRecommand =
        UtilSp.getBool(AppConstant.LocationSearchRecommend, defValue: true);
    state.historyRecomand =
        UtilSp.getBool(AppConstant.SearchHistoryRecommend, defValue: true);

    state.recommandStatus = state.positionRecommand && state.historyRecomand;
  }

  bool updateRecommandStatus(bool value) {
    state.recommandStatus = value;
    updateHistoryRecomand(value);
    updatePositionRecommand(value);
    return value;
  }

  bool updateHistoryRecomand(bool value) {
    state.historyRecomand = value;
    UtilSp.putBool(AppConstant.SearchHistoryRecommend, value);
    state.recommandStatus = state.positionRecommand && state.historyRecomand;
    return value;
  }

  bool updatePositionRecommand(bool value) {
    state.positionRecommand = value;
    UtilSp.putBool(AppConstant.LocationSearchRecommend, value);
    state.recommandStatus = state.positionRecommand && state.historyRecomand;
    return value;
  }
}
